/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AddNewOrderJPanel.java
 *
 * Created on Jun 8, 2011, 12:39:52 PM
 */
package presentation.guiForFundamentalFilter;

import business.fundamentalCenter.Custom;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JDialog;

/**
 *
 * @author Dinh
 */
public class AddNewCriteriaJPanel extends javax.swing.JPanel {

    /**
	 * 
	 */
    private static final long serialVersionUID = 1L;
    private JDialog parent;
    private String criteria;
    private Double min;
    private Double max;
    private boolean ok = false;

    
    public String getCriteria() {
        return criteria;
    }

    public Double getMax() {
        return max;
    }

    public Double getMin() {
        return min;
    }
    
    public boolean isOk() {
        return ok;
    }


    /** Creates new form AddNewOrderJPanel */
    public AddNewCriteriaJPanel(JDialog jDialog) {
        this.parent = jDialog;
        initComponents();
        initOtherComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        priceJLabel = new javax.swing.JLabel();
        minJSpinner = new javax.swing.JSpinner();
        volumeJLabel = new javax.swing.JLabel();
        maxJSpinner = new javax.swing.JSpinner();
        cancelJButton = new javax.swing.JButton();
        okJButton = new javax.swing.JButton();
        exchangeJLabel = new javax.swing.JLabel();
        criteriaJComboBox = new javax.swing.JComboBox();

        priceJLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        priceJLabel.setText("Min:");

        minJSpinner.setModel(new javax.swing.SpinnerNumberModel(Double.valueOf(0.0d), null, null, Double.valueOf(0.1d)));

        volumeJLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        volumeJLabel.setText("Max:");

        maxJSpinner.setModel(new javax.swing.SpinnerNumberModel(Double.valueOf(0.0d), null, null, Double.valueOf(0.1d)));

        cancelJButton.setText("Cancel");
        cancelJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelJButtonActionPerformed(evt);
            }
        });

        okJButton.setText("OK");
        okJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okJButtonActionPerformed(evt);
            }
        });

        exchangeJLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        exchangeJLabel.setText("Criteria:");

        criteriaJComboBox.setEditable(true);
        criteriaJComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                criteriaJComboBoxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(exchangeJLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(criteriaJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(priceJLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(minJSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(volumeJLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(maxJSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(okJButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelJButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelJButton, okJButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exchangeJLabel)
                    .addComponent(criteriaJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(priceJLabel)
                    .addComponent(minJSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(volumeJLabel)
                    .addComponent(maxJSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelJButton)
                    .addComponent(okJButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void okJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okJButtonActionPerformed
        //Add new order
        ok = true;

        criteria = (String) criteriaJComboBox.getSelectedItem();
        min = (Double) minJSpinner.getValue();
        max = (Double) maxJSpinner.getValue();

        this.parent.dispose();
    }//GEN-LAST:event_okJButtonActionPerformed

    private void cancelJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelJButtonActionPerformed
        ok = false;
        this.parent.dispose();
    }//GEN-LAST:event_cancelJButtonActionPerformed

    private void criteriaJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_criteriaJComboBoxActionPerformed
}//GEN-LAST:event_criteriaJComboBoxActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelJButton;
    private javax.swing.JComboBox criteriaJComboBox;
    private javax.swing.JLabel exchangeJLabel;
    private javax.swing.JSpinner maxJSpinner;
    private javax.swing.JSpinner minJSpinner;
    private javax.swing.JButton okJButton;
    private javax.swing.JLabel priceJLabel;
    private javax.swing.JLabel volumeJLabel;
    // End of variables declaration//GEN-END:variables

    private void initOtherComponents() {

//        if (DataVisualizationJPanel.mappingExchangeID_Assets == null) {
//            DataVisualizationJPanel.mappingExchangeID_Assets = new TreeMap<ExchangeEntity, Object[]>();
//            ArrayList<ExchangeEntity> listAllExchangeEntitys = (new ExchangeManager()).getAllExchanges();
//            for (ExchangeEntity exchangeEntity : listAllExchangeEntitys) {
//                ArrayList<AssetEntity> listAssets = (new AssetManager()).getAssetsByExchange(exchangeEntity.getExchangeID());
//                DataVisualizationJPanel.mappingExchangeID_Assets.put(exchangeEntity, listAssets.toArray());
//            }
//        }

        criteriaJComboBox.setModel(new DefaultComboBoxModel(Custom.STAT_LIST));
    }

    public JDialog getParentDialog() {
        return this.parent;
    }
}
